package com.jshx.sz.gdjt.util;

import android.content.Context;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.os.Environment;
import android.telephony.TelephonyManager;

/**
 * 获取设备相关信息的类
 * @author xiangchangan
 * @time 2013-08-20
 */
public class DeviceUtil {
	
	private static String ESN = "";
	
	private static String IMSI = "";

	// 获取ESN
	public static String getESN(Context context) {
		if (ESN == null || ESN.equals("") || ESN.length() == 0) {
			try {
				TelephonyManager telephonyManager = (TelephonyManager) context
						.getSystemService(Context.TELEPHONY_SERVICE);
				ESN = telephonyManager.getDeviceId();
			} catch (Exception ex) {

			}
		}
		return ESN;
	}

	// 获取IMSI
	public static String getIMSI(Context context) {
		if (IMSI == null || IMSI.equals("") || IMSI.length() == 0) {
			try {
				TelephonyManager telephonyManager = (TelephonyManager) context
						.getSystemService(Context.TELEPHONY_SERVICE);
				IMSI = telephonyManager.getSubscriberId();
			} catch (Exception ex) {

			}
		}
		return IMSI;
	}
	
	/**
	 * 
	 * @param context
	 * @return
	 */
	public static boolean checkNetWorkReady(Context context) {
		ConnectivityManager conMan = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		android.net.NetworkInfo.State mobile = conMan.getNetworkInfo(
				ConnectivityManager.TYPE_MOBILE).getState();
		if (mobile == android.net.NetworkInfo.State.CONNECTED) {
			return true;
		}
		else
		{
			mobile=conMan.getNetworkInfo(
					ConnectivityManager.TYPE_WIFI).getState();
			if (mobile == android.net.NetworkInfo.State.CONNECTED) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * 
	 * @return
	 */
	public static boolean checkSDCardReady()
	{
		if(Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * 
	 * @return
	 */
	public static boolean checkGPSEnable(Context context)
	{
		LocationManager lm = (LocationManager)context
				.getSystemService(Context.LOCATION_SERVICE);
		return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
	}
}
